package com.example.lkqapp14;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;

import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.BottomSheetDialogFragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    private boolean isOpen = false;
    private LinearLayout mBottomSheet;
    private BottomSheetBehavior bottomSheetBehavior;
    private Button btnOnOff;
    private BottomNavigationBar bottomNavigationBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mBottomSheet = findViewById(R.id.bottom_sheet);
        bottomSheetBehavior = BottomSheetBehavior.from(mBottomSheet);

        bottomNavigationBar = findViewById(R.id.id_bnb);
        bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.doubleup, "A").setActiveColor(Color.RED).setInActiveColor(Color.YELLOW));
        bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.doubleup, "B").setActiveColor(Color.GREEN));
        bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.doubleup, "C").setActiveColor(Color.GRAY));
        bottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.doubleup, "D").setActiveColor(Color.BLUE));
        bottomNavigationBar.initialise();

        bottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.SimpleOnTabSelectedListener() {
            @Override
            public void onTabSelected(int position) {
                super.onTabSelected(position);
                ToastUtil.showAtOnce(MainActivity.this,"第" + position + "被选中");
            }

            @Override
            public void onTabUnselected(int position) {
                super.onTabUnselected(position);
            }

            @Override
            public void onTabReselected(int position) {
                super.onTabReselected(position);
            }
        });

        bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
            @Override
            public void onStateChanged(@NonNull View view, int newState) {
                //Toast.makeText(MainActivity.this, "newState:" + newState, Toast.LENGTH_SHORT).show();
                ToastUtil.showAtOnce(MainActivity.this, "newState:" + newState);
            }

            @Override
            public void onSlide(@NonNull View view, float v) {
                Log.e(TAG,"onslide = " + v);
            }
        });

        btnOnOff = findViewById(R.id.btn_on_off);
        btnOnOff.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isOpen){
                    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
                } else {
                    bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
                }

                isOpen = !isOpen;


            // 对话框
            /*BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(MainActivity.this);
            bottomSheetDialog.setContentView(R.layout.a_pome_item);
            bottomSheetDialog.show();*/

            BottomSheetDialogFragment fragment = new MyBottomSheetDialogFragment();
            fragment.show(getSupportFragmentManager(),"fragment");

            }

        });

        findViewById(R.id.tv1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btnOnOff.setBackgroundColor(Color.RED);
            }
        });

    }
}
